﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace MINERP.CleanupTool
{
    public delegate void ControlThreadHander(bool isStart);
    public delegate void ShowErrMsgHander(string msg);
    public delegate void RefreshStatusHander();
    public delegate void ShowNotifyMsgHander(string msg);
    public delegate void InitProcessBar(int TotalNum);
    public delegate void CompleteNotifyHander();
    public delegate void SetTotalNumHander(int num);
    public delegate void SetCurrentNumHander(int num);

    public partial class FrmStatus : Form
    {
        public ControlThreadHander controlThreadHander;

        public FrmStatus()
        {
            InitializeComponent();
        }

        private void FrmStatus_Load(object sender, EventArgs e)
        {
            progressBarStatus.Maximum = 100;
            progressBarStatus.Minimum = 0;
        }

        public void ShowErrMsg(string msg)
        {
            if (lbxErrMsg.InvokeRequired)
            {
                ShowErrMsgHander showMsg = new ShowErrMsgHander(ShowErrMsg);
                this.Invoke(showMsg, new object[] { msg});
            }
            else
            {
                lbxErrMsg.Items.Add(msg);
            }
        }

        public void SetProcessBar()
        {
            if (progressBarStatus.InvokeRequired)
            {
                RefreshStatusHander refreshStatus = new RefreshStatusHander(SetProcessBar);
                this.Invoke(refreshStatus);
            }
            else
            {
                if (progressBarStatus.Value < progressBarStatus.Maximum)
                {
                    progressBarStatus.Value += 1;
                }
            }
        }
        public void ShowNotifyMsg(string msg)
        {
            if (txtStatus.InvokeRequired)
            {
                ShowNotifyMsgHander showMsg = new ShowNotifyMsgHander(ShowNotifyMsg);
                this.Invoke(showMsg, new object []{msg});
            }
            else
            {
                txtStatus.Text = msg;
            }
        }

        public void InitProcessBar(int total)
        {
            if (progressBarStatus.InvokeRequired)
            {
                InitProcessBar initProcessBar = new InitProcessBar(InitProcessBar);
                this.Invoke(initProcessBar, new object[] { total });
            }
            else
            {
                progressBarStatus.Maximum = total;
                progressBarStatus.Minimum = 0;
            }
 
        }


        public void SetTotalNum(int num)
        {
            lbtotal.Text = num.ToString();
        }

        public void SetCurrentNum(int num)
        {
            lbCurrent.Text = num.ToString();
        }

        private void FrmStatus_FormClosing(object sender, FormClosingEventArgs e)
        {
            controlThreadHander.Invoke(false);
        }




        private void btnStop_Click(object sender, EventArgs e)
        {
            controlThreadHander.Invoke(false);
        }
    }
}
